package flc.ast.adapter;

import android.graphics.Color;
import android.graphics.PorterDuff;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.constraintlayout.utils.widget.ImageFilterView;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyCameraFilterBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class CameraFilterAdapter extends StkProviderMultiAdapter<MyCameraFilterBean> {

    public CameraFilterAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(76));
        addItemProvider(new CameraFilterProvider());
    }

    private class CameraFilterProvider extends BaseItemProvider<MyCameraFilterBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_filter;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyCameraFilterBean bean) {
            baseViewHolder.setText(R.id.tvPictureFilterItemName, bean.getName());
            ImageFilterView view = baseViewHolder.getView(R.id.ivPictureFilterItemImg);
            view.setColorFilter(Color.parseColor(bean.getColor()), PorterDuff.Mode.LIGHTEN);
            if (bean.isSelect()) {
                baseViewHolder.getView(R.id.tvPictureFilterItemSel).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.ivPictureFilterItemSel).setVisibility(View.VISIBLE);

            } else {
                baseViewHolder.getView(R.id.tvPictureFilterItemSel).setVisibility(View.INVISIBLE);
                baseViewHolder.getView(R.id.ivPictureFilterItemSel).setVisibility(View.INVISIBLE);
            }
        }
    }
}
